# 根据需要对交易数据进行统计
import matplotlib.pyplot as plt
from pylab import mpl
import stock_data_deal
# 从数据库中查询数据
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False

code = "600825"
# name = "新华传媒"
# code = "000100"
# name = "TCL科技"
# code = "603501"
# name = "韦尔股份"
# code = "601360"
# name = "三六零"
# code = "002230"
# name = "科大讯飞"

data_list = stock_data_deal.getDealStatistic(code)
# 数据准备
x = [obj.deal_date.strftime('%Y-%m-%d') for obj in data_list]
y1 = [obj.buy_num for obj in data_list]
y2 = [obj.mid_num for obj in data_list]
y3 = [obj.sale_num for obj in data_list]
y4 = [obj.buy_num - obj.sale_num  for obj in data_list]

# 创建图形和轴对象
fig, ax = plt.subplots()

# 绘制折线图，并自定义样式和添加图例
ax.plot(x, y1, label='主动买入', color='red', linestyle='-', marker='o')  # 实线，圆圈标记
ax.plot(x, y2, label='中性操作', color='gray', linestyle='-', marker='o')  # 实线，圆圈标记
ax.plot(x, y3, label='主动卖出', color='green', linestyle='-', marker='o')  # 点线，方块标记
ax.plot(x, y4, label='买卖差值', color='orange', linestyle='--', marker='s')  # 点线，方块标记

# 添加标题和轴标签，显示图例
ax.set_title(data_list[0].name)
ax.set_xlabel('时间')
ax.set_ylabel('数量')
ax.legend()  # 显示图例

# 设置坐标轴范围和网格线
# ax.set_xlim(0, 6)  # 设置X轴范围从0到6
# ax.set_ylim(0, 20)  # 设置Y轴范围从0到20
ax.grid(True)  # 显示网格线

# 显示图形
plt.show()


